package bid.web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

@WebServlet(name = "HelloServlet",value = "/hello")
public class HelloServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //request就是内置对象的request
        //response就是内置对象的response
        response.setContentType("text/html;charset=UTF-8");
       //request.getParameter()
        ////>>>response.sendRedirect("");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<body>");
        out.println("<h1>");
        out.println("这是一个post请求，现在是："+new Date());
        out.println("</h1>");
        out.println("</body>");
        out.println("</html>");


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
        response.setContentType("text/html;charset=UTF-8");

        PrintWriter out = response.getWriter();

        out.println("<html>");
        out.println("<body>");
        out.println("<h1>");
        out.println("这是一个get请求，现在是："+new Date());
        out.println("</h1>");

        out.println("</body>");
        out.println("</html>");

        request.getRequestDispatcher("/WEB-INF/hello.jsp").forward(request,response);
    }
}
